package com.daka.service.impl;

import com.daka.dao.UserPassportApplyOrderMapper;
import com.daka.entity.BaseAddress;
import com.daka.entity.UserPassportApplyOrder;
import com.daka.service.BaseAddressService;
import com.daka.service.UserPassportApplyOrderService;
import com.daka.vo.Page;
import com.daka.vo.request.PassportRequestVo;
import com.daka.vo.response.passport.PassportResponseCMS;
import com.daka.vo.response.passport.PassportResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangx
 * CreateTime: 2016/10/25 8:59
 */
@Service("userPassportApplyOrderService")
@SuppressWarnings("unused")
public class UserPassportApplyOrderServiceImpl implements UserPassportApplyOrderService {

    @Autowired
    private UserPassportApplyOrderMapper userPassportApplyOrderMapper;
    @Autowired
    private BaseAddressService baseAddressService;



    @Override
    public int insert(UserPassportApplyOrder po) {
        return userPassportApplyOrderMapper.insert(po);
    }

    @Override
    public int update(UserPassportApplyOrder po) {
        return userPassportApplyOrderMapper.updateByPrimaryKeySelective(po);
    }

    @Override
    public UserPassportApplyOrder selectByPrimaryKey(Long id) {
        return userPassportApplyOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<PassportResponseVo> selectPageByStatement(PassportRequestVo po) {

        po.setPageNo(20*po.getPageNo());
        po.setPageSize(20);
        List<UserPassportApplyOrder> list = userPassportApplyOrderMapper.selectByStatement(po);
        List<PassportResponseVo> list1 = new ArrayList<>();
        if(list.size()>0){
            for(UserPassportApplyOrder aa:list){
                BaseAddress baseAddress = baseAddressService.selectById(aa.getBassAddressId());
                list1.add(PassportResponseVo.buildVO(aa, baseAddress));
            }
        }
        int count =  userPassportApplyOrderMapper.selectByStatementCount(po);
        Page<PassportResponseVo>  page = new Page<>();
        page.setTotalCount(count);
        page.setData(list1);
        return page;
    }

    @Override
    public Page<PassportResponseVo> selectPageByDate(PassportRequestVo po) {
        po.setPageNo(20*po.getPageNo());
        po.setPageSize(20);
        List<UserPassportApplyOrder> list = userPassportApplyOrderMapper.selectPageByDate(po);
        List<PassportResponseVo> list1 = new ArrayList<>();
        if(list.size()>0){
            for(UserPassportApplyOrder aa:list){
                BaseAddress baseAddress = baseAddressService.selectById(aa.getBassAddressId());
                list1.add(PassportResponseVo.buildVO(aa, baseAddress));
            }
        }
        int count =  userPassportApplyOrderMapper.selectPageByDateCount(po);
        Page<PassportResponseVo>  page = new Page<>();
        page.setTotalCount(count);
        page.setData(list1);
        return page;
    }

    @Override
    public List<UserPassportApplyOrder> selectByStatement(PassportRequestVo po) {
        return userPassportApplyOrderMapper.selectByStatement(po);
    }

    @Override
    public int selectByStatementCount(PassportRequestVo po) {
        return userPassportApplyOrderMapper.selectByStatementCount(po);
    }

    @Override
    public Page<PassportResponseCMS> selectPageByAddress(PassportRequestVo po) {
        po.setPageNo(20 * po.getPageNo());
        po.setPageSize(20);
        List<UserPassportApplyOrder> list = userPassportApplyOrderMapper.selectPageByAddress(po);
        List<PassportResponseCMS> list1 = new ArrayList<>();
        if(list.size()>0){
            for(UserPassportApplyOrder aa:list){
                BaseAddress baseAddress = baseAddressService.selectById(aa.getBassAddressId());
                list1.add(PassportResponseCMS.buildVO(aa, baseAddress));
            }
        }
        int count = userPassportApplyOrderMapper.selectPageByAddressCount(po);
        Page<PassportResponseCMS>  page = new Page<>();
        page.setTotalCount(count);
        page.setData(list1);
        return page;
    }

    @Override
    public List<UserPassportApplyOrder> selectDetByOrder(PassportRequestVo po) {
        return userPassportApplyOrderMapper.selectDetByOrder(po);
    }

}
